package com.cicigodd.brick.plug.system.role.controller;

import com.cicigodd.brick.plug.annotation.repeatsubmit.RepeatSubmit;
import com.cicigodd.brick.plug.annotation.resource.DeleteResource;
import com.cicigodd.brick.plug.annotation.resource.PutResource;
import com.cicigodd.brick.plug.common.response.PageResult;
import com.cicigodd.brick.plug.common.response.Result;
import com.cicigodd.brick.plug.common.response.ResultGenerator;
import com.cicigodd.brick.plug.annotation.resource.PostResource;
import com.cicigodd.brick.plug.annotation.resource.GetResource;
import com.cicigodd.brick.plug.system.role.request.SysRoleMenuAddRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleMenuDeleteRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleMenuDetailRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleMenuEditRequest;
import com.cicigodd.brick.plug.system.role.request.SysRoleMenuListRequest;
import com.cicigodd.brick.plug.system.role.response.SysRoleMenuDetailResponse;
import com.cicigodd.brick.plug.system.role.response.SysRoleMenuListResponse;
import com.cicigodd.brick.plug.system.role.service.SysRoleMenuService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;


@ApiIgnore
@Api(tags = "角色菜单关联")
@RestController
public class SysRoleMenuController {

    @Resource
    private SysRoleMenuService sysRoleMenuService;

    @RepeatSubmit
    @ApiOperation(value = "角色菜单关联添加", notes = "角色菜单关联添加")
    @PostResource(name = "角色菜单关联添加", path = "/sysRoleMenu/add")
    public Result add(@RequestBody @Validated SysRoleMenuAddRequest sysRoleMenuAddRequest) {
        sysRoleMenuService.add(sysRoleMenuAddRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "角色菜单关联删除", notes = "根据id删除")
    @DeleteResource(name = "角色菜单关联删除", path = "/sysRoleMenu/delete")
    public Result delete(@Validated SysRoleMenuDeleteRequest sysRoleMenuDeleteRequest) {
        sysRoleMenuService.delete(sysRoleMenuDeleteRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "角色菜单关联编辑", notes = "角色菜单关联编辑")
    @PutResource(name = "角色菜单关联编辑", path = "/sysRoleMenu/edit")
    public Result edit(@RequestBody @Validated SysRoleMenuEditRequest sysRoleMenuEditRequest) {
        sysRoleMenuService.edit(sysRoleMenuEditRequest);
        return ResultGenerator.successResult();
    }


    @ApiOperation(value = "角色菜单关联详情", notes = "根据id查询")
    @GetResource(name = "角色菜单关联详情", path = "/sysRoleMenu/detail")
    public Result<SysRoleMenuDetailResponse> detail(SysRoleMenuDetailRequest sysRoleMenuDetailRequest) {
        SysRoleMenuDetailResponse detail = sysRoleMenuService.detail(sysRoleMenuDetailRequest);
        return ResultGenerator.successResult(detail);
    }


    @ApiOperation(value = "角色菜单关联分页列表", notes = "角色菜单关联分页列表")
    @GetResource(name = "角色菜单关联分页列表", path = "/sysRoleMenu/list")
    public Result<PageResult<SysRoleMenuListResponse>> list(SysRoleMenuListRequest sysRoleMenuListRequest) {
        PageResult<SysRoleMenuListResponse> pageList =  sysRoleMenuService.list(sysRoleMenuListRequest);
        return ResultGenerator.successResult(pageList);
    }
}
